package com.baomidou.springwind.test.IO;

import java.io.*;

/**
 * Created by Administrator on 2017/3/12.
 */
public class Blips3 implements Externalizable {
    private String s;
    private int i;

    public Blips3() {
        System.out.println("public Blips3()");

    }
    public Blips3(int i, String s) {
        System.out.println(" public Blips3(int i, String s):");
        this.i = i;
        this.s = s;
    }

    @Override
    public String toString() {
        return s + i;
    }

    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        System.out.println("writeExternal");
        out.writeInt(i);
        out.writeObject(s);
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        System.out.println("readExternal");
        i = in.readInt();
        s = (String) in.readObject();
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Blips3 blips3 = new Blips3(47, "A String");
        System.out.println(blips3);

        ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream("F:\\code\\SpringWind\\SpringWind\\src\\main\\java\\com\\baomidou\\springwind\\test\\IO\\Blips3.out"));
        System.out.println("Saving object");
        out.writeObject(blips3);
        out.close();

        ObjectInputStream ois = new ObjectInputStream(
                new FileInputStream("F:\\code\\SpringWind\\SpringWind\\src\\main\\java\\com\\baomidou\\springwind\\test\\IO\\Blips3.out"));
        blips3 = (Blips3) ois.readObject();
        System.out.println("Recovering b3");
        System.out.println(blips3);
    }
}
